package uk.co.q3c.deplan.client.ui.component;

import java.util.ArrayList;
import java.util.List;

import uk.co.q3c.deplan.client.util.DoubleString;

import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.Hyperlink;

/**
 * @see ReferenceWidget
 * @author David Sowerby 2 May 2010
 * 
 */
public class ReferenceListWidget extends CaptionPanel {
	private String labelText;
	private List<Hyperlink> hyperlinks;

	/**
	 * 
	 */
	public ReferenceListWidget() {
		super();
		hyperlinks = new ArrayList<Hyperlink>();
	}

	/**
	 * @param captionText
	 */
	public ReferenceListWidget(String captionText) {
		super(captionText);
	}

	public String getLabelText() {
		return labelText;
	}

	public void setLabelText(String labelText) {
		this.labelText = labelText;
	}

	public List<DoubleString> getDataValue() {
		List<DoubleString> result = new ArrayList<DoubleString>();
		for (Hyperlink h : hyperlinks) {
			DoubleString ds = new DoubleString(h.getText(), h.getTargetHistoryToken());
			result.add(ds);
		}
		return result;
	}

	public void addItem(String text, String targetHistoryToken) {
		Hyperlink h = new Hyperlink();
		h.setText(text);
		h.setTargetHistoryToken(targetHistoryToken);
		add(h);
		hyperlinks.add(h);
	}

	public void setDataValue(List<DoubleString> items) {
		for (DoubleString ds : items) {
			addItem(ds.part1, ds.part2);
		}
	}

}
